package com.harmontronics.hanma.paas.paas.controller;

import java.util.Arrays;
import java.util.List;

import cn.hutool.core.bean.BeanUtil;
import com.harmontronics.hanma.paas.paas.common.ResponseEntity;
import com.harmontronics.hanma.paas.paas.common.PageBase;
import cn.hutool.core.convert.Convert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.harmontronics.hanma.paas.paas.service.HmBaseModuleComponentAppService;
import com.harmontronics.hanma.paas.paas.dto.iam.output.HmBaseModuleComponentResult;
import com.harmontronics.hanma.paas.paas.dto.iam.input.HmBaseModuleComponentCreateInput;
import com.harmontronics.hanma.paas.paas.dto.iam.input.HmBaseModuleComponentUpdateInput;
import com.harmontronics.hanma.paas.paas.domain.iam.entity.HmBaseModuleComponent;
import com.harmontronics.hanma.paas.paas.utils.ParamUtils;

import javax.validation.Valid;


/**
 * 模块对应的各种组件 根据 type进行区分
 *
 * @author paas-generator
 * @email paas-generator@harmontronics.com
 * @date 2021-04-27 11:08:41
 */
@RestController
@RequestMapping("/api/hmbasemodulecomponent")
@Api(tags = {"模块对应的各种组件 根据 type进行区分"})
public class HmBaseModuleComponentController {
    @Autowired
    private HmBaseModuleComponentAppService hmBaseModuleComponentappService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApiOperation("列表")
    public ResponseEntity<List<HmBaseModuleComponentResult>> list() {
        List<HmBaseModuleComponent> hmBaseModuleComponentList = hmBaseModuleComponentappService.getList();

        return ResponseEntity.ok(Convert.toList(HmBaseModuleComponentResult.class, hmBaseModuleComponentList));
    }


    /**
     * 信息
     */
    @GetMapping("/info")
    @ApiOperation("详情")
    public ResponseEntity<HmBaseModuleComponentResult> info(@RequestParam Long id) {
        HmBaseModuleComponent hmBaseModuleComponent =hmBaseModuleComponentappService.findById(id);
            HmBaseModuleComponentResult result = BeanUtil.toBean(hmBaseModuleComponent,HmBaseModuleComponentResult.class);
        return ResponseEntity.ok(result);
    }


    /**
     * 分页列表
     */
    @GetMapping("/page/list")
    @ApiOperation("分页列表")
    public ResponseEntity<PageBase<HmBaseModuleComponentResult>> list(@ApiParam(value = "页码", defaultValue = "1") @RequestParam(required = false, defaultValue = "1") int pageNo,
            @ApiParam(value = "每页数据条数", defaultValue = "20") @RequestParam(required = false, defaultValue = "20") int pageSize,
            @RequestParam String type) {
        PageBase<HmBaseModuleComponent> hmBaseModuleComponentPageBase = hmBaseModuleComponentappService.getList(pageNo, pageSize,type);
        PageBase<HmBaseModuleComponentResult> resultPageBase = PageBase.copy(hmBaseModuleComponentPageBase,HmBaseModuleComponentResult.class);
        return ResponseEntity.ok(resultPageBase);
    }



    @PostMapping
    @ApiOperation(value = "创建BaseModuleComponent")
    public ResponseEntity create(@RequestBody HmBaseModuleComponentCreateInput hmBaseModuleComponentInput) {
        HmBaseModuleComponent hmBaseModuleComponent =BeanUtil.toBean(hmBaseModuleComponentInput,HmBaseModuleComponent. class);
        hmBaseModuleComponentappService.save(hmBaseModuleComponent);
        return ResponseEntity.ok();
    }


    /**
     * 修改
     */
    @PutMapping
    @ApiOperation("修改")
    public ResponseEntity<String> update(@Valid @RequestBody HmBaseModuleComponentUpdateInput hmBaseModuleComponentInput) {
        HmBaseModuleComponent hmBaseModuleComponent =BeanUtil.toBean(hmBaseModuleComponentInput,HmBaseModuleComponent. class);
        hmBaseModuleComponentappService.update(hmBaseModuleComponent);
        return ResponseEntity.ok();
    }


    /**
     * 删除
     */
    @DeleteMapping()
    @ApiOperation("删除")
    public ResponseEntity<String> delete(@RequestBody Long[] ids) {
        hmBaseModuleComponentappService.remove(Arrays.asList(ids));

        return ResponseEntity.ok();
    }

}
